package com.plian.system.service.pm.realproperty.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.plian.Tools.StringUtil;
import com.plian.system.entity.pm.realproperty.RealProperty;
import com.plian.system.enumeratea.LandStatus;
import com.plian.system.mapper.pm.realproperty.RealPropertyMapper;
import com.plian.system.mybatis.base.BaseServiceImpl;
import com.plian.system.service.pm.realproperty.IRealPropertyLatestService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 不动产信息 最新 服务实现类
 *
 * @author BladeX
 * @since 2021-06-01
 */
@Slf4j
@Service
@AllArgsConstructor
public class RealPropertyLatestServiceImpl extends BaseServiceImpl<RealPropertyMapper, RealProperty> implements IRealPropertyLatestService {


    @Override
    public RealProperty findByInitialId(Long initialId) {
        return getOne(new LambdaQueryWrapper<RealProperty>().eq(RealProperty::getInitialId, initialId)
                .eq(RealProperty::getIsLatest, 2).ne(RealProperty::getLandStatus, LandStatus.DISPOSAL.getStatus()));
    }

    @Override
    public List<RealProperty> findLatestList(String orgId, String fillingUnitId) {
        LambdaQueryWrapper<RealProperty> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(RealProperty::getIsLatest, 2);
        queryWrapper.ne(RealProperty::getLandStatus, LandStatus.DISPOSAL.getStatus());
        if (StringUtil.isNotBlank(orgId)){
            queryWrapper.eq(RealProperty::getOrgId, orgId);
        }
        if (StringUtil.isNotBlank(fillingUnitId)){
            queryWrapper.eq(RealProperty::getFillingUnitId, fillingUnitId);
        }
        queryWrapper.orderByDesc(RealProperty::getCreateTime);
        return list(queryWrapper);
    }
}
